package schoolbolg_gh326.Adapter;

import java.util.List;

import schoolbolg_gh326.Bean.BlogsBean;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.schoolbolg_gh326.R;
import com.squareup.picasso.Picasso;

public class BlogsAdapter extends BaseAdapter {
	private LayoutInflater inflater;
	private Context context;
	private List<BlogsBean> list;
	public BlogsAdapter(Context context, List<BlogsBean> list) {
		this.inflater = LayoutInflater.from(context);
		this.context = context;
		this.list = list;
		
		
	}
	public void setList(List<BlogsBean> list){
		this.list = list;
	}
	
	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return list.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return list.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return  position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		ViewHolder holder=null;
		if (convertView==null) {
			convertView = inflater.inflate(R.layout.blog_item, null);
			holder = new ViewHolder();
			holder.thumb = (ImageView) convertView.findViewById(R.id.thumb);
			holder.name =(TextView) convertView.findViewById(R.id.name);
			holder.intro = (TextView) convertView.findViewById(R.id.intro);
			convertView.setTag(holder);
			
		}
		else 
			holder = (ViewHolder) convertView.getTag();
			  holder.intro.setText(list.get(position).getIntro());
			    holder.name.setText(list.get(position).getName());
			    Picasso.with(context).load("http://amicool.neusoft.edu.cn/Uploads/"+list.get(position).getThumb()).into(holder.thumb);
				  
			    return convertView;
	}
	public static class ViewHolder {
		ImageView thumb;
		TextView name;
		TextView intro;
		
		
	}

}
